package com.lee.lease.web.app.controller.history;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lee.lease.common.result.Result;
import com.lee.lease.common.util.JwtUtil;
import com.lee.lease.web.app.service.BrowsingHistoryService;
import com.lee.lease.web.app.vo.history.HistoryItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * ClassName: HistoryController
 * Package: com.lee.lease.web.app.controller.history
 * Description:
 */
@RestController
@RequestMapping("/app/history")
@Tag(name = "浏览历史管理")
public class HistoryController {

    @Autowired
    private BrowsingHistoryService browsingHistoryService;

    @Operation(summary = "获取浏览历史")
    @GetMapping("/pageItem")
    public Result getPageItem(Integer current, Integer size, @RequestHeader("access_token") String token){
        Integer userId = JwtUtil.parseToken(token).get("userId", Integer.class);
        IPage<HistoryItemVo> page = new Page(current,size);
        Map data= browsingHistoryService.findPage(page,userId);

        return Result.ok(data);
    }
}
